/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package generatorGraphics.graphics;

import grammaticalClasses.nwConsole.ShowStatCur;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Paint;
import java.util.ArrayList;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Heitor
 */
public class ChgConsumption extends Graph {
    
    public ChgConsumption(){
        name = "ChgConsumption";
        help = "Help of Charge Consumption";
        
        configUnitOptions();
        
        commands.add("ShowStatCur");
    }
    
    private void configUnitOptions(){

        // Adicionando as unidades
        //--Não existe definição de Opções
        
        //Adicionando as opções
        //--Não existe definição de Opções
    }
    
    @Override
    protected void createGraph(String unit){
        
        int indice;
        
        switch (unit){
            case "":                
                indice = search.getAnswer(commands, "ShowStatCur");
                chartPanel = new ChartPanel(buildGraph((ArrayList<ShowStatCur>) answer.get(indice)));
                chartPanel.setBackground(Color.LIGHT_GRAY);
                chartPanel.setPreferredSize(new Dimension(700, 350)); 
                chartPanel.setDomainZoomable(false);
                chartPanel.setRangeZoomable(false);
                
                break;
            default:
                chartPanel = new ChartPanel(null);
                break;
        }        
    }
    
    private JFreeChart buildGraph(ArrayList<ShowStatCur> auxCur){
    
        ShowStatCur aux = auxCur.get(0);
        
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for(int j=0; j< aux.getMoteStats().size(); j++){
            dataset.setValue(aux.getMoteStats().get(j).getChg(), 
                "Charge Consumption", aux.getMoteStats().get(j).getId() + "Id");
        }
        JFreeChart chart = ChartFactory.createBarChart("Chg Consumption in " 
            + aux.getTime().toString() + " seconds",
            "Devices", "mC", dataset, 
            PlotOrientation.VERTICAL, false, true, false);
        chart.setBackgroundPaint(new Color(238, 238, 238));

        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.black);
        BarRenderer rend = (BarRenderer) p.getRenderer();
        rend.setSeriesPaint(0, Color.BLUE);
                
        return chart;
        
    }
    
    @Override
    public ChartPanel getChartPanel() {
        
        if(search != null){
            createGraph("");
            return chartPanel;
        } else {
            return new ChartPanel(null);
        }
    }
}
